﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KBWebApi.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KBWebApi.Controllers
{
    /// <summary>
    /// 维护机台数据
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class WorkStationController : ControllerBase
    {
        Bll.WorkStationBll workStationBll = new Bll.WorkStationBll();

        /// <summary>
        /// 获取全部数据列表(分页查询)
        /// </summary>
        /// <param name="WorkShopId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetAllList")]
        public async Task<ActionResult> GetAllList(string WorkShopId)
        {
            var result = await workStationBll.GetAllList(WorkShopId);
            return new JsonResult(
                new
                {
                    code = 20000,
                    message = result
                }

            );
        }

        /// <summary>
        /// 新增或修改机台数据
        /// </summary>
        /// <param name="workStation"></param>
        /// <returns></returns>
        [HttpPost]
        //[WabApiAuthorize]
        [Route("NewOrUpdate")]
        public async Task<ActionResult> NewOrUpdate(WorkStationModel workStation)
        {
            if (workStation == null)
            {
                return new JsonResult(new
                {
                    code = 20001,
                    message = "失败"
                });
            }

            var result = await workStationBll.NewOrUpdate(workStation);
            return result;
        }

        /// <summary>
        /// 根据ID删除机台数据
        /// </summary>
        /// <param name="WorkStationId"></param>
        /// <returns></returns>
        [HttpGet]
        //[WabApiAuthorize]
        [Route("Delete")]
        public async Task<ActionResult> Delete(string WorkStationId)
        {
            if (string.IsNullOrEmpty(WorkStationId))
            {
                return new JsonResult(new
                {
                    code = 20001,
                    message = "失败"
                });
            }

            var result = await workStationBll.Delete(WorkStationId);
            return result;
        }
    }
}